package project.euler.honk.problem.to50;

public final class Problem39 {

	private static int getNumSolutions(int p) {

		int count = 0;
		
		for (int a = 3; a < p - 2; a++) {
			for (int b = a; a + b < p; b++) {
				int tmp = (p - a - b) * (p - a - b);
				int tmp2 = (a * a) + (b * b);
				if(tmp == tmp2) {
					count++;
				} else if (tmp < tmp2) {
					break;
				}
			}
		}

		return count;
	}

	public static int solve() {
		int max = 0;
		int maxP = 0;
		for(int i = 0; i <= 1000; i++) {
			int tmp = getNumSolutions(i);
			if(max < tmp) {
				max = tmp;
				maxP = i;
			}
		}
		return maxP;
	}

	public static void main(String[] args) {
		long start = System.currentTimeMillis();
		int result = solve();
		long end = System.currentTimeMillis();
		System.out.println("Result: " + result + " Time: " + (end - start));
	}

}
